package site.zhouinfo.spider;

import java.util.HashSet;
import java.util.Set;

/**
 * 记录已访问过的URL和待访问的URL
 * Author: zhouinfo
 * mySite: www.zhouinfo.site
 * Create Date：2016-03-23 23:37
 */
public class LinkQueue {

	//已访问的URL集合
	private static Set visitedUrl = new HashSet();

	private static Queue unVisitedUrl = new Queue();

	public static Queue getUnVisitedUrl() {
		return unVisitedUrl;
	}

	public static void addVisitedUrl(String url) {
		visitedUrl.add(url);
	}

	public static void removeVisitedUrl(String url) {
		visitedUrl.remove(url);
	}

	public static Object unVisitedUrl() {
		return unVisitedUrl.deQueue();
	}

	public static void addUnvisitedUrl(String url) {
		if (url != null && !url.trim().equals("") && !visitedUrl.contains(url) && !unVisitedUrl.contians(url)) {
			unVisitedUrl.enQueue(url);
		}
	}

	public static int getVisitedUrlNum() {
		return visitedUrl.size();
	}

	public static boolean unVisitedUrlIsEmpty() {
		return unVisitedUrl.isQueueEmpty();
	}

}
